<?php
// 连接数据库
require '../script/mysqlconfig.php';
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
    die("连接数据库失败: " . $conn->connect_error);
}

$search_room = $_POST["search_room"];
$search_cabinet = $_POST["search_cabinet"];
$search_belongen  = $_POST["search_belongen"];
$search_belongop = $_POST["search_belongop"];

// 查询数据库
$sql = "SELECT * FROM hosts where room like '$search_room' and cabinet like '$search_cabinet' and belong_en like '$search_belongen' and belong_op like '$search_belongop' ";

$result = $conn->query($sql);

// 生成表格
if ($result->num_rows > 0) {
    echo "<table border='1' style='border-collapse: collapse;'>";
    echo "<tr><th>ID</th><th>设备品牌</th><th>型号</th><th>序列号</th><th>设备类型</th><th>所在机房</th><th>机柜</th><th>开始U位</th><th>结束U位</th><th>设备使用状态</th><th>设备的用途</th><th>带外IP地址</th><th>管理IP地址</th><th>业务IP地址</th><th>设备归属</th><th>资产归属部门</th><th>资产归属人员</th><th>公司资产编码</th><th>设备使用部门</th><th>设备使用人</th><th>客户号</th><th>客户名字</th><th>备注</th></tr>";
    while ($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["id"]."</td><td>".$row["brand"]."</td><td>".$row["model"]."</td><td>".$row["serial_number"]."</td><td>".$row["device_type"]."</td><td>".$row["room"]."</td><td>".$row["cabinet"]."</td><td>".$row["start_u"]."</td><td>".$row["end_u"]."</td><td>".$row["device_status"]."</td><td>".$row["device_feature"]."</td><td>".$row["bmc_ip"]."</td><td>".$row["manage_ip"]."</td><td>".$row["yewu_ip"]."</td><td>".$row["device_belong"]."</td><td>".$row["belong_en"]."</td><td>".$row["belong_op"]."</td><td>".$row["asset_code"]."</td><td>".$row["use_en"]."</td><td>".$row["use_operator"]."</td><td>".$row["client_no"]."</td><td>".$row["client_name"]."</td><td>".$row["other"]."</td></tr>";
    }
    echo "</table>";
} else {
    echo "数据库中没有数据";
}

// 关闭数据库连接
$conn->close();
?>